package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.domain.dto.TrainingIpPoolDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.TrainingIpPool;
import com.ruoyi.training.service.ITrainingIpPoolService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * IP池Controller
 * 
 * @author rocc
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/pool")
public class TrainingIpPoolController extends BaseController
{
    @Autowired
    private ITrainingIpPoolService trainingIpPoolService;

    /**
     * 查询IP池列表
     */
    @RequiresPermissions("training:pool:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainingIpPool trainingIpPool)
    {
        startPage();
        List<TrainingIpPool> list = trainingIpPoolService.selectTrainingIpPoolList(trainingIpPool);
        return getDataTable(list);
    }

    /**
     * 导出IP池列表
     */
    @RequiresPermissions("training:pool:export")
    @Log(title = "IP池", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainingIpPool trainingIpPool)
    {
        List<TrainingIpPool> list = trainingIpPoolService.selectTrainingIpPoolList(trainingIpPool);
        ExcelUtil<TrainingIpPool> util = new ExcelUtil<TrainingIpPool>(TrainingIpPool.class);
        util.exportExcel(response, list, "IP池数据");
    }

    /**
     * 获取IP池详细信息
     */
    @RequiresPermissions("training:pool:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(trainingIpPoolService.selectTrainingIpPoolById(id));
    }

    /**
     * 新增IP池
     */
    @RequiresPermissions("training:pool:add")
    @Log(title = "IP池", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainingIpPool trainingIpPool)
    {
        return toAjax(trainingIpPoolService.insertTrainingIpPool(trainingIpPool));
    }

    /**
     * 修改IP池
     */
    @RequiresPermissions("training:pool:edit")
    @Log(title = "IP池", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainingIpPool trainingIpPool)
    {
        return toAjax(trainingIpPoolService.updateTrainingIpPool(trainingIpPool));
    }

    @RequiresPermissions("training:pool:insertPool")
    @Log(title = "IP池", businessType = BusinessType.INSERT)
    @PostMapping("/betweenBatchInsert")
    public AjaxResult betweenBatchInsert(@RequestBody TrainingIpPoolDto trainingIpPoolDto)
    {
        return toAjax(trainingIpPoolService.betweenBatchInsert(trainingIpPoolDto));
    }

    /**
     * 删除IP池
     */
    @RequiresPermissions("training:pool:remove")
    @Log(title = "IP池", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainingIpPoolService.deleteTrainingIpPoolByIds(ids));
    }
}
